********************************************************************************
** 	TITLE: e12_acr_weights.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Figure XII: Average Causal Response Weights
**
********************************************************************************

set sortseed 13
 	use "$output_data/estimate.dta", replace

	mat R=J(50,5,.)

			//stay ignite_0 for Recidivism
				cap drop stay
				gen stay = stay_rec
				cap drop ignite_0
				gen ignite_0 = ignite_0_rec

forvalues x=1/35{
	cap drop temp_`x'
	gen temp_`x'=stay>=`x'
//Pre-IGNITE
		reghdfe temp_`x'  D_remove_any $auxiliary_control ///
			if D_ignite_proxy ==0 , ///
			cluster(inmate) a($design_control)
		mat R[`x',1] = _b[D_remove_any]
		mat R[`x',2] = _se[D_remove_any]

//Post-IGNITE
		reghdfe temp_`x'  D_remove_any $auxiliary_control ///
			if D_ignite_proxy ==1, ///
			cluster(inmate) a($design_control)
		mat R[`x',4] = _b[D_remove_any]
		mat R[`x',5] = _se[D_remove_any]
		
	mat R[`x',3]=`x'
	drop temp_`x'
}


preserve 

/*********************************************************************************
Panel (a) Estimated Weights
**********************************************************************************/	
svmat R
keep R1-R5
keep if !mi(R1)
ren (R1 R2 R3 R4 R5) (b se month b1 se1)

gen ub=b+1.96*se
gen lb=b-1.96*se
gen ub1=b1+1.96*se1
gen lb1=b1-1.96*se1

tw (line ub month, lp(dash) lc(ebblue) ) ///
	(line lb month, lp(dash) lc(ebblue)) ///
	(connected b month, lp(solid) lc(ebblue) mc(ebblue) msymbol(O) msize(small)) ///
	(line ub1 month if b1!=0, lp(dash) lc(black) ) ///
	(line lb1 month if  b1!=0, lp(dash) lc(black)) ///
	(connected b1 month if  b1!=0, lp(solid) lc(black) mc(black) msymbol(O) msize(small)) ///
	, ///
	legend(pos(6) order(3 "Pre-IGNITE" 6 "Post-IGNITE")) xtitle("Months") ///
	ytitle("Rescheduling Effect on" "Pr(incarcerated for at least t months)") ///
	yline(0,lc(black)) xlab(0(5)35) ylab(0(.02).12)

	gr export "$figures/fs_monthly_all.pdf", replace

restore

/*********************************************************************************
Panel (b) Pre- vs. Post-IGNITE Difference
**********************************************************************************/			

	cap drop *_xpost
	foreach v in $design_control $auxiliary_control {
		gen `v'_xpost = `v'*D_ignite_proxy
	}

	
	mat R=J(50,5,.)
forvalues x=1/35{
	cap drop temp_`x'
	gen temp_`x'=stay>=`x'

		reghdfe temp_`x' interact_proxy_any D_remove_any D_ignite_proxy $auxiliary_control ///
			, ///
			cluster(inmate) a($design_control *_xpost)
		mat R[`x',1] = _b[interact_proxy_any]
		mat R[`x',2] = _se[interact_proxy_any]

	mat R[`x',3]=`x'
	drop temp_`x'
}



preserve 

svmat R
keep R1-R5
keep if !mi(R1)
ren (R1 R2 R3) (b se month)

gen ub=b+1.96*se
gen lb=b-1.96*se


tw (line ub month, lp(dash) lc(ebblue) ) ///
	(line lb month, lp(dash) lc(ebblue)) ///
	(connected b month, lp(solid) lc(ebblue) mc(ebblue) msymbol(O) msize(small)) ///
	, ///
	legend(off) xtitle("Months") ///
	ytitle("Rescheduling Effect on" "Pr(incarcerated for at least t months)") ///
	yline(0,lc(black)) xlab(0(5)35)  ylab(-0.06(.03).12)

	gr export "$figures/fs_monthly_diff_all.pdf", replace
restore 
